package chapter11;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.*;


/**
 * Created with IntelliJ IDEA.
 * Description:
 *
 * @author lzy
 * @create 2018-03-23 上午9:01
 */
public class CombineFileTest {
    private static final Logger LOGGER = LoggerFactory.getLogger(CombineFileTest.class);

    public static void main(String[] args) {
        File file1 = new File(File.separator + "home" + File.separator + "lzy" + File.separator + "logs" + File.separator + "test" + File.separator + "dt1.dat");
        File file2 = new File(File.separator + "home" + File.separator + "lzy" + File.separator + "logs" + File.separator + "test" + File.separator + "dt2.dat");
        try (InputStream input1 = new FileInputStream(file1);
             InputStream input2 = new FileInputStream(file2);
             ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
            byte[] temp = new byte[5];
            int len = 0;
            while ((len = input1.read(temp)) != -1) {
                outputStream.write(temp, 0, len);
            }
            while ((len = input2.read(temp)) != -1) {
                outputStream.write(temp, 0, len);
            }
            byte[] result = outputStream.toByteArray();
            LOGGER.info("[combine result]:{}", new String(result));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
